package com.mars.base.common.base;

import java.io.Serializable;
import java.util.Map;

import com.mars.base.common.enums.HttpCode;
import com.mars.base.common.utils.I18nMessage;

public class BaseResult implements Serializable {

	private static final long serialVersionUID = 1L;

	/**
     * 响应状态
     */
    private Boolean status ;

    /**
     * 响应代码
     */
    private Integer code ;

    /**
     * 响应消息
     */
    private String message ;

    /**
     * 响应数据
     */
    private Object data ;

    /**
     * 其他属性数据
     */
    private Map<String, Object> attrs ;

    /**
     * 当前时间
     */
    private Long timestamp = System.currentTimeMillis() ;

    public BaseResult() {}

    public BaseResult(Boolean status, Integer code, String message, Object data, Map<String, Object> attrs) {
        super();
        this.status = status;
        this.code = code;
        this.message = message;
        this.data = data;
        this.attrs = attrs;
    }

    public static BaseResult build(Boolean status, Integer code, String message, Object data, Map<String, Object> attrs) {
        return new BaseResult(status, code, message, data, attrs) ;
    }
    public static BaseResult build(Integer code, String message, Object data, Map<String, Object> attrs) {
        return new BaseResult(null, code, message, data, attrs) ;
    }
    public static BaseResult build(Integer code, String message, Object data) {
        return new BaseResult(null, code, message, data, null) ;
    }
    public static BaseResult build(Integer code, String message, Map<String, Object> attrs) {
        return new BaseResult(null, code, message, null, attrs) ;
    }
    public static BaseResult build(Integer code, String message) {
        return new BaseResult(null, code, message, null, null) ;
    }
    public static BaseResult build(Boolean status, String message, Object data, Map<String, Object> attrs) {
        return new BaseResult(status, null, message, data, attrs) ;
    }
    public static BaseResult build(Boolean status, String message, Object data) {
        return new BaseResult(status, null, message, data, null) ;
    }
    public static BaseResult build(Boolean status, String message, Map<String, Object> attrs) {
        return new BaseResult(status, null, message, null, attrs) ;
    }
    public static BaseResult build(Boolean status, String message) {
        return new BaseResult(status, null, message, null, null) ;
    }

    public static BaseResult build(Boolean status, Integer code, String message) {
        return new BaseResult(status, code, message, null, null) ;
    }
    public static BaseResult build(Boolean status, HttpCode httpCode, Object...args) {
        return new BaseResult(status, httpCode.getValue(), I18nMessage.getMessage(httpCode.msg(), args), null, null) ;
    }
    public static BaseResult build(HttpCode httpCode, Object...args) {
        return new BaseResult(null, httpCode.getValue(), I18nMessage.getMessage(httpCode.msg(), args), null, null) ;
    }


    public static BaseResult ok(HttpCode httpCode, Object data, Map<String, Object> attrs, Object...args) {
        return new BaseResult(true, httpCode.getValue(), I18nMessage.getMessage(httpCode.msg(), args), data, attrs) ;
    }
    public static BaseResult ok(HttpCode httpCode, Object...args) {
        return new BaseResult(true, httpCode.getValue(), I18nMessage.getMessage(httpCode.msg(), args), null, null) ;
    }
    public static BaseResult ok(String okMsg) {
    	return new BaseResult(true, HttpCode.OK.getValue(), okMsg, null, null) ;
    }
    public static BaseResult ok() {
        return new BaseResult(true, HttpCode.OK.getValue(), I18nMessage.getMessage(HttpCode.OK.msg()), null, null) ;
    }

    public static BaseResult failure(HttpCode httpCode, Object data, Map<String, Object> attrs, Object...args) {
        return new BaseResult(false, httpCode.getValue(), I18nMessage.getMessage(httpCode.msg(), args), data, attrs) ;
    }
    public static BaseResult failure(HttpCode httpCode, Object...args) {
        return new BaseResult(false, httpCode.getValue(), I18nMessage.getMessage(httpCode.msg(), args), null, null) ;
    }
    public static BaseResult failure(String errorMsg) {
    	return new BaseResult(false, HttpCode.INTERNAL_SERVER_ERROR.getValue(), errorMsg, null, null) ;
    }
    public static BaseResult failure() {
        return new BaseResult(false, HttpCode.INTERNAL_SERVER_ERROR.getValue(), I18nMessage.getMessage(HttpCode.INTERNAL_SERVER_ERROR.msg()), null, null) ;
    }

    public static BaseResult addOk() {
        return new BaseResult(true, HttpCode.ADD_OK.getValue(), I18nMessage.getMessage(HttpCode.ADD_OK.msg()), null, null) ;
    }
    public static BaseResult addFailed() {
        return new BaseResult(false, HttpCode.ADD_FAILED.getValue(), I18nMessage.getMessage(HttpCode.ADD_FAILED.msg()), null, null) ;
    }

    public static BaseResult deleteOk() {
        return new BaseResult(true, HttpCode.DELETE_OK.getValue(), I18nMessage.getMessage(HttpCode.DELETE_OK.msg()), null, null) ;
    }
    public static BaseResult deleteFailed() {
        return new BaseResult(false, HttpCode.DELETE_FAILED.getValue(), I18nMessage.getMessage(HttpCode.DELETE_FAILED.msg()), null, null) ;
    }

    public static BaseResult updateOk() {
        return new BaseResult(true, HttpCode.UPDATE_OK.getValue(), I18nMessage.getMessage(HttpCode.UPDATE_OK.msg()), null, null) ;
    }
    public static BaseResult updateFailed() {
        return new BaseResult(false, HttpCode.UPDATE_FAILED.getValue(), I18nMessage.getMessage(HttpCode.UPDATE_FAILED.msg()), null, null) ;
    }

    public static BaseResult loadOk() {
        return new BaseResult(true, HttpCode.LOAD_OK.getValue(), I18nMessage.getMessage(HttpCode.LOAD_OK.msg()), null, null) ;
    }
    public static BaseResult loadOk(Object data) {
        return new BaseResult(true, HttpCode.LOAD_OK.getValue(), I18nMessage.getMessage(HttpCode.LOAD_OK.msg()), data, null) ;
    }
    public static BaseResult loadFailed() {
        return new BaseResult(false, HttpCode.LOAD_FAILED.getValue(), I18nMessage.getMessage(HttpCode.LOAD_FAILED.msg()), null, null) ;
    }


    public Boolean getStatus() {
        return status;
    }

    public void setStatus(Boolean status) {
        this.status = status;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Map<String, Object> getAttrs() {
        return attrs;
    }

    public void setAttrs(Map<String, Object> attrs) {
        this.attrs = attrs;
    }

    public Long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(Long timestamp) {
        this.timestamp = timestamp;
    }

    @Override
    public String toString() {
        return "BaseResult [status=" + status + ", code=" + code + ", message=" + message + ", data=" + data + ", attrs=" + attrs + ", timestamp=" + timestamp + "]";
    }
}
